$('#cd_info ol li').each(function() {
	var song = $(this).text();
	var artist = $(this).children('a').dataset('artist');
	var album = $(this).children('a').dataset('album');
	
	var value_string = song+' by '+artist+' on '+album;
	
	$(this).prepend("<span class=\"play\" onclick=\"_gaq.push(['_trackEvent', 'CD review song', 'play', '"+value_string+"']);\">play</span> ");
	
	// loading text doesn't display unless parent has class "active"
	$(this).append('<p id="loading_text">loading...</p>');
});

// retrieve grooveshark player embed code
$('#cd_info ol li .play').live('click', function() {
	$(this).parent().attr('id', 'loading');
	$(this).parent().addClass('active');
	
	var song = $(this).parent().children('a').text();
	var artist = $(this).parent().children('a').dataset('artist');
	var album = $(this).parent().children('a').dataset('album');
	
	$.ajax({
		url: "http://tastemakersmag.com/wp-content/themes/tays-t/ajax/grooveshark_player.php",
		type: "POST",
		data: 'song='+song+'&artist='+artist+'&album='+album,
		dataType: "html",
		async: false,
		success: function(player_code) {
			$('#loading .play').text('close');
			$('#loading .play').removeAttr('onclick');
			$('#loading .play').removeClass('play').addClass('close');
			$('#loading #loading_text').remove();
			$('#loading').append(player_code);
			$('#loading').removeAttr('id');
		}
	});
});

$('#cd_info ol li .close').live('click', function() {
	$(this).parent().children('object').remove();
	$(this).parent().removeClass('active');
	$(this).removeClass('close').addClass('play');
	$(this).text('play');
});

// this part actually shortens the track list

// go through each listed track and hide everything after the 6th track
$('#cd_info ol li').each(function(index) {
	if (index >= 5) {
		$(this).hide();
	}
});

$('#cd_info ol').append('<li>... <a id="view_full_tracklist" href="javascript:;">view full tracklist</a></li>');

$('#view_full_tracklist').live('click', function() {
	$(this).parent().remove();
	$('#cd_info ol li').show();
});